<?php
namespace App\Model\BbcModel;

use Service\Code\Normal;
use App\Model\BaseModel\BaseBbcModel;

/**
 * 店铺关联主表
 */
class StoreRelation extends BaseBbcModel {

    public $table = 'ly_store_relation';

    /**
     * 获取关联的店铺
     */
    public static function getStore($param){
        $mnUserinfo = Mnuser::where('mid', $param['mid'])->where('pid', $param['cid'])->where('status', 1)->where('check_status', 1)->select(['id','store_name'])->first();
        if(!$mnUserinfo){
            return [];
        }
        $mnUserinfo = $mnUserinfo->toArray();
        $id=self::where('cid', $param['cid'])->where('mn_sid', $mnUserinfo['id'])->value('id');
        if(empty($id)){
            return [];
        }
        $viceIds=ViceStore::where('main_id', $id)->where('cid', $param['cid'])->where('main_mn_sid', $mnUserinfo['id'])->pluck('vice_mn_sid')->toArray();
        $store = Mnuser::where('pid','=',$param['cid'])->where('new_store','=',1)->where('check_status','=',1)->where('status','=',1)->whereIn('id', $viceIds)->select(['id','store_name'])->get();
        if($store->isEmpty()){
            return $mnUserinfo;
        }
        $storeArr = $store->toArray();
        array_push($storeArr,$mnUserinfo);
        return $store;
    }

}